{extend name="public::base" /}

{block name="content"}
<div class="col-md-8">
    <div class="page-header">
        <h2>{$art.cate_id|getCateName}</h2>
    </div>
    <div>
        <div>
            <h4>{$art.title}</h4>
            <p>
                发布者：{$art.user_id|getUserName}&nbsp;&nbsp;&nbsp;&nbsp;
                发布时间:{$art.create_time}&nbsp;&nbsp;&nbsp;&nbsp;
                阅读量：{$art.pv}
            </p>
            <div>{$art.content|getArtContent}</div>
            <hr>
            <button class="btn btn-default" data-user_id="{$Think.session.user_info.id|intval}" type="button" id="fav" data-article_id="{$art.id}">收藏</button>
        </div>
    </div>
</div>
{/block}

{block name="footer"}
<script type="text/javascript">
$(function () {
    $('#fav').on('click',function () {
        var sender = $(this);
        if(sender.attr('data-user_id') == 0){
            alert('请先登录');location.href = "{:url('user/login')}";return;
        }
        $.ajax({
            url:"{:url('doFav')}",
            dataType:'json',
            data:{'article_id':sender.attr('data-article_id')},
            success:function (res) {
                if(res.status == 0){
                    alert(res.msg);return;
                }
                if(res.status == 1){
                    // 收藏
                    sender.attr('class', 'btn btn-success');
                }else{
                    // 取消收藏
                    sender.attr('class', 'btn btn-default');
                }
                sender.text(res.msg);
                return;
            }
        });
    });
});
</script>
{/block}